﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>微街秀 > 注册</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" type="text/css" href="css/css.css" />
    <link href="css/registered.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/base.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            $('#submits').click(function () { submits(); });
            $("#timg").click(function () {
                if ($("#timg").attr("src") == "img/6.jpg") {
                    $("#timg").attr("src", "img/10.jpg")
                }
                else {
                    $("#timg").attr("src", "img/6.jpg")
                }
            });

            var a = getSession("a");
            if (a == null || a == '')
                a = getCookie('a');
            if (a != null && (!isNaN(a)))
                $("#agentid").val(a);
        });
        function submits() {
            var param = { "login_type": 1, "name": trim($('#name').val()), "pwd": trim($('#pwd').val()), "email": trim($('#email').val()), "phone": trim($('#phone').val()), "agentid": trim($('#agentid').val()) };
            if (!check(param)) return false;

            Alert("正在注册...");
            $.post("ajax/user.ashx?regist", param, function (data) {
                if (data.code == 0) {
                    Alert("注册成功...");
                    SetCookie("token", data.item.token);
                    SetCookie("userid", data.item.id);
                    SetCookie("logintype", "1");
                    delCookie("a");
                    window.location.href = "personal.html?userid=" + data.item.id + "&token=" + data.item.token;
                } else
                    Alert(data.msg)
            },
            "json");
        }

        function check(param) {
            if (param.name == "") {
                Alert("请输入账号");
                $('#name').focus();
                return false;
            }
            if (param.pwd == "") {
                Alert("请输入密码");
                $('#pwd').focus();
                return false;
            }
            if (param.pwd !=$("#pwd2").val()) {
                Alert("密码不一致");
                $('#pwd2').focus();
                return false;
            }
            if (param.email == "") {
                Alert("请输入邮箱");
                $('#email').focus();
                return false;
            }
            if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(param.email)) {
                Alert("邮箱格式不正确");
                $('#email').focus();
                return false;
            }

            if (param.phone == "") {
                Alert("请输入电话");
                $('#phone').focus();
                return false;
            }
            if (isNaN(param.agentid)) {
                Alert("推荐人ID必须是数字");
                $('#phone').focus();
                return false;
            }
            var reg = new RegExp("^[0-9]*$");
            if (!reg.test(param.agentid)) {
                Alert("推荐人ID必须是数字");
                return;
            }
            if (!checkMobile(param.phone)) {
                Alert("电话格式不正确");
                $('#phone').focus();
                return false;
            }
            return true;
        }
        //点提交后锁定，5秒后允许再次提交
        function SleepClick() {

        }

  
        /* 
        * 功能：判断用户输入的手机号格式是否正确 
        * 传参：无 
        * 返回值：true or false 
        */
        function checkMobile(s) {
            var regu = /^1\d{10}$/;
            var molie = /^0\d{2,3}-?\d{7,8}$/;
            var reg400 = /^400-([0-9]){1}([0-9-]{7})$/;

            var moliereg = new RegExp(molie);
            var re400 = new RegExp(reg400);
            var re = new RegExp(regu);

            if (re400.test(s) || moliereg.test(s) || re.test(s)) {
                return true;
            } else {
                return false;
            }
        } 
    </script>
</head>
<body>
    <div class="wamtop">
        <div class="topleft" onclick="window.location.href='login.html'">
          
                <img src="img/5.jpg">
         
        </div>
        <div class="topcententxt">
            注册
        </div>
    </div>
    <div class="box1" style=" margin-top:10%;">
        用户名 :
        <input type="text" id="name" name="name" class="input" placeholder="此项为必填项" maxlength="32">
    </div>
    <div class="box1">
        密码 :
        <input type="password" id="pwd" name="pwd" class="input" placeholder="此项为必填项" maxlength="32">
    </div>
    <div class="box1">
        确认密码 :
        <input type="password" id="pwd2" name="pwd2" class="input" placeholder="此项为必填项" maxlength="32">
    </div>
    <div class="box1">
        邮箱 :
        <input type="text" id="email" name="email" class="input" placeholder="此项为必填项">
    </div>
    <div class="box1">
        手机号 :
        <input type="text" id="phone" name="phone" class="input" placeholder="此项为必填项" maxlength="14">
    </div>
     <div class="box1">
        推荐人ID :
        <input type="text" id="agentid" name="agentid" class="input" placeholder="数字格式可以不填" maxlength="8">
    </div>
    <div class="zhongbu">
        <div class="ziti" style=" font-size:12px;">
            <img src="img/6.jpg" id="timg">我已阅读并同意<a href="xieyi.html"><span style="color: #F37E10;">注册协议</span></a></div>
    </div>
    </div>
    <div class="box2">
        <div id="submits" class="input2">
            确定</div>
    </div>
    <a href="javascript:" onclick="window.location.href='login.html'">
        <div class="box4">
            立即登录</div>
    </a>
    <div style="margin-top: 50px;">
    </div>
</body>
</html>
